home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9507 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.luc.edu!user
  2. From: VArase@varase.it.luc.edu (Verne Arase)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: malloc question
  5. Date: Mon, 11 Mar 1996 10:02:54 -0600
  6. Organization: LUMC
  7. Message-ID: <AD69AACE9668D78B0@mcdiala09.it.luc.edu>
  8. References: <4htonk$350@news.hklink.net> <4huctt$arv@sparcserver.lrz-muenchen.de> <314318AF.30F@iperbole.bologna.it> <4hvaj4$laj@solutions.solon.com>
  9. NNTP-Posting-Host: 147.126.240.109
  10.  
  11. In article <4hvaj4$laj@solutions.solon.com>,
  12. seebs@solutions.solon.com (Peter Seebach) wrote:
  13.  
  14.  >>Error?!? Why do you think that casting is an error? The standard ANSI
  15.  >>runtime library says:
  16.  >
  17.  >He didn't say it was an error, he said it could *hide* an error.
  18.  
  19. Well, in the general case it _could_ hide an error.
  20.  
  21. In this specific case, however, it _never_ hides an error. If malloc is
  22. used in its standard context, we are simply coercing a slab of memory
  23. aligned to the most stringent boundaries into a pointer of the desired
  24. type.
  25.  
  26. Provided the associated header is included (and the memory model doesn't
  27. change through some devious, manual manipulation), you are _always_ safe in
  28. coercing a malloc allocated block of memory into the desired pointer type.
  29.  
  30. ***** flame on ******
  31. This is one reason I stopped participating in C conferences; there's always
  32. some language lawyer who'll tell a novice that a cast is an evil (even if
  33. it has to do with casting a char * to an unsigned char * for use in a file
  34. name). What they normally fail to tell you is that any code much beyond the
  35. sophistication of "Hello World" practically requires casts to produce
  36. workable code.
  37.  
  38. IMO, making a char a signed quantity (along with the infamous misplacement
  39. of the boolean and operator's priority) have made more C programmer's lives
  40. miserable than any other construct in any other language (that I've
  41. encountered).
  42.  
  43. Sure there are constructs that'll get you in trouble. But let us not forget
  44. that C is the original "gun, bullet, foot" language, and requires care in
  45. its use and execution.
  46. ***** flame off *****
  47.  
  48. ---
  49. The above are my own opinions, and not those of my employer.
  50.